package io.kiki.sba.registry.common.model.metaserver;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.Nulls;
import io.kiki.sba.registry.compress.CompressConstants;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.Set;

@JsonIgnoreProperties(ignoreUnknown = true)
public class CompressPushSwitch {
    @Getter
    @Setter
    private boolean enabled = false;

    @Setter
    @JsonSetter(nulls = Nulls.SKIP)
    private int compressMinSize = CompressConstants.defaultCompressPushMinSize;

    @Getter
    @JsonSetter(nulls = Nulls.SKIP)
    private Set<String> forbidEncodes = Collections.emptySet();

    @Getter
    @JsonSetter(nulls = Nulls.SKIP)
    private Set<String> enabledSessions = Collections.emptySet();

    @Getter
    @JsonSetter(nulls = Nulls.SKIP)
    private Set<String> enabledClients = Collections.emptySet();

    public CompressPushSwitch() {
    }

    public static CompressPushSwitch defaultSwitch() {
        return new CompressPushSwitch();
    }


    public void setForbidEncodes(Set<String> encodes) {
        if (CollectionUtils.isEmpty(encodes)) {
            forbidEncodes = Collections.emptySet();
        } else {
            forbidEncodes = encodes;
        }
    }

    public void setEnabledSessions(Set<String> sessions) {
        if (CollectionUtils.isEmpty(sessions)) {
            enabledSessions = Collections.emptySet();
        } else {
            enabledSessions = sessions;
        }
    }

    public void setEnabledClients(Set<String> clients) {
        if (CollectionUtils.isEmpty(clients)) {
            enabledClients = Collections.emptySet();
        } else {
            enabledClients = clients;
        }
    }


    public int getCompressMinSize() {
        return compressMinSize;
    }
}
